package main

import (
	"github.com/labstack/echo/v4"
	"golang.org/x/net/websocket"
)

func main() { //20200727
	e := echo.New()

	e.GET("/ws", func(c echo.Context) error {
		handler := websocket.Handler(func(conn *websocket.Conn) {
			readString(conn)

			conn.Write([]byte("ok"))
			println("send client : ok")
		})
		handler.ServeHTTP(c.Response().Writer, c.Request())
		return nil
	})
	e.Start(":11111")
}

func readString(conn *websocket.Conn) {
	var msg = make([]byte, 1024)
	read, err := conn.Read(msg)
	if err != nil {
		println(err)
	}
	println("from client : ", string(msg[:read]))
}
